package com.stylefeng.guns.modular.area.util;

import com.stylefeng.guns.modular.area.model.BdapArea;
import com.stylefeng.guns.modular.area.model.BdapAreaPopPropHm;

/**
 * 
 * ClassName: AreaUtil
 * 
 * @Description: 区域工具类，用于计算客流密度，告警级别，客流增速
 * @author xiongyao
 * @date 2017年11月24日
 */
public class AreaUtil {

	/**
	 * 
	 * @Description: 计算客流密度
	 * @param @return
	 * @return String
	 * @throws
	 * @author xiongyao
	 * @date 2017年11月24日
	 */
	public static String getPassengerDensity(BdapArea area,
			BdapAreaPopPropHm areaPopPropHm) {
		if (area != null && areaPopPropHm != null) {
			double passengerDensity = Double.parseDouble(areaPopPropHm
					.getTotalUsers()) / area.getSaturationValue() * 100;
			return String.format("%.2f", passengerDensity) + "%";
		} else {
			return "暂无";
		}
	}

	/**
	 * 
	 * @Description: 计算客流密度
	 * @param @return
	 * @return String
	 * @throws
	 * @author xiongyao
	 * @date 2017年11月24日
	 */
	public static String getPassengerDensity(Integer saturationValue,
			Integer totalUser) {
		double passengerDensity = totalUser / saturationValue * 100;
		return String.format("%.2f", passengerDensity) + "%";
	}

	/**
	 * 
	 * @Description: 计算告警级别
	 * @param @return
	 * @return String
	 * @throws
	 * @author xiongyao
	 * @date 2017年11月24日
	 */
	public static String getWarnLevel(BdapArea area,
			BdapAreaPopPropHm areaPopPropHm) {
		if (area != null && areaPopPropHm != null
				&& area.getWarningValue() != null
				&& area.getSaturationValue() != null
				&& area.getSevereValue() != null) {
			long nowUc = Long.parseLong(areaPopPropHm.getTotalUsers());
			int warnUc = area.getWarningValue();// 警戒
			int statWarnUc = area.getSaturationValue();// 饱和
			int servWarnUc = area.getSevereValue();// 严重
			if (nowUc >= servWarnUc) {
				return "严重";
			}
			if (nowUc >= statWarnUc) {
				return "饱和";
			}
			if (nowUc >= warnUc) {
				return "告警";
			}
			return "正常";
		} else {
			return "暂无";
		}
	}

	/**
	 * 
	 * @Description: 临时计算未来一小时客流预测
	 * @param @return
	 * @return String
	 * @throws
	 * @author xiongyao
	 * @date 2017年11月24日
	 */
	public static String getNextHourUc(BdapAreaPopPropHm nowareaPopPropHm,
			BdapAreaPopPropHm areaPopPropHmbefore) {
		if (areaPopPropHmbefore == null || nowareaPopPropHm == null) {
			return "暂无";
		}
		double nowUc = Double.parseDouble(nowareaPopPropHm.getTotalUsers());
		double beforeUc = Double.parseDouble(areaPopPropHmbefore
				.getTotalUsers());
		if (nowUc == 0 || beforeUc == 0) {
			return String.valueOf(nowUc);
		} else {
			return String.valueOf(nowUc / beforeUc * nowUc).split("\\.")[0];
		}
	}

	/**
	 * 
	 * @Description: 计算客流增速
	 * @param @return
	 * @return String
	 * @throws
	 * @author xiongyao
	 * @date 2017年11月24日
	 */
	public static String getPassengerFlowGrowth(
			BdapAreaPopPropHm nowareaPopPropHm,
			BdapAreaPopPropHm areaPopPropHmbefore) {
		if (areaPopPropHmbefore == null || areaPopPropHmbefore == null) {
			return "暂无";
		}
		long nowUc = Long.parseLong(nowareaPopPropHm.getTotalUsers());
		long beforeUc = Long.parseLong(areaPopPropHmbefore.getTotalUsers());
		return nowUc - beforeUc + "";
	}

}
